<?php
/**
 * $Id: IndexController.php 423 2008-05-30 14:42:41Z dakl $
 * Strona glowna
 *
 */
class IndexController extends MainController implements ControllerInterface {
	
    
    //o - order
	//v - order vector
	//t - total items to select
	public $tableConfig = array(
		'product_table_main' => array(
			'o' => array(
				'id' => 'product.id_product',
				'serial' => 'product.code',
				'name' => 'product_description.name',
				'_' => 'id'
			),
			'v' => 'malejaco',
			't' => 10
		),
		'infopts_table' => array(
			'o' => array(
				'id' => 'image_map.id_image_map',
				'name' => 'image_map_description.title',
				'_' => 'id'
			),
			'v' => 'malejaco',
			't' => 10
		)
	);
    
    
    /**
	 * strona glowna
	 *
	 */
	public function IndexAction($param) {
		$this->AddDescription(' ');
                $this->AddTitle(' ');
	}
        
        public function ProductsAction($param) {
            $this->AddDescription(' ');
                $this->AddTitle(' ');
            $lang = Registry::Get('default_language_id');
		$dal = ProductDAL::GetDalDataObj(array(
			'tableData' => $this->tableParams['product_table_main'],
			'join' => array(
				'ProductDescription' => ' LEFT JOIN product_description ON(product.id_product = product_description.id_product AND product_description.id_language = '.Registry::Get('default_language_id').')',
                                'ProductShop'        => ' INNER JOIN product_shop ON(product.id_product = product_shop.id_product)'
			)
		));
                $dal->addCondition('id_shop', Registry::Get('shopObj')->getId());

		if(Request::IsPost() && Request::Check('id_manufacturer')) {
			$data = Request::GetAllPost();
			SessionProxy::SetValue('product_filter',serialize($data));
			$this->addRedirect(Router::GenerateUrl('productIndex',array('product' => 'index')),0);
		}

		if(SessionProxy::IsSetValue('product_filter')) {
			$data = SessionProxy::GetValue('product_filter');
			$data = unserialize($data);

			$filtering = false;

			if($data['id_manufacturer'] > 0) {
				$dal->addCondition('id_manufacturer',$data['id_manufacturer']);
				$filtering = true;
			}

			if($data['id_category'] > 0) {
				$dal->addCondition('id_category',$data['id_category']);
				$filtering = true;
			}

			if(strlen($data['code']) > 0) {
				$dal->addCondition('code',$data['code']);
				$filtering = true;
			}

			if(strlen($data['name']) > 0) {
				$dal->addCondition('product_description.name',"'%".$data['name']."%'",'LIKE');
				$filtering = true;
			}

			if($filtering){
				$this->smarty->assign('filter',$data);
			}else{
				SessionProxy::ClearValue('product_filter');
			}
		}

		$list = ProductDAL::GetResult($dal);
		$dal->setCount(true);
		$dal->setLimit('');
		$count = ProductDAL::GetResult($dal);

		$this->smarty->assign('list',$list);
		$this->smarty->assign('c',$count);
        }
	
	/**
	 * Metoda wspolna
	 *
	 */
	public function preDispatch($param) {
            $this->RunShared('Auth');
            $this->Run($param);
            $this->smarty->assign('param_from_url',$param);
        
	}
	/**
	 * 
	 *
	 */
	public function postDispatch($param) {
	}
}
